package com.supervision.student;

import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;

import android.Manifest;
import android.annotation.SuppressLint;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import com.supervision.student.util.SaveNum;

import java.util.Map;

public class MainActivity extends AppCompatActivity {

    Button btnNum, btnCall, btnSOS;
    String phone;
    String password;
    String webIp;
    String parentPhone;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        //获取控件
        btnNum = findViewById(R.id.btn_num);
        btnCall = findViewById(R.id.btn_call);
        btnSOS = findViewById(R.id.btn_sos);

        Map<String, String> userInfo = SaveNum.getUserInfo(this);
        if (userInfo != null) {
            phone=userInfo.get("phone");
            password=userInfo.get("password");
            webIp=userInfo.get("webIp");

        }

        btnNum.setOnClickListener(new View.OnClickListener() {
            @Override
            @SuppressLint("MissingPermission")
            public void onClick(View v) {
                jump();
            }
        });


        //拨打电话
        btnCall.setOnClickListener(new View.OnClickListener() {
            @SuppressLint("MissingPermission")
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:"+parentPhone));
                startActivity(intent);
                System.out.println(123);
            }
        });

        //SOS
        btnSOS.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Thread sosThread = new SOSThread(phone,webIp);
                sosThread.start();
            }
        });
    }

    void jump(){
        Intent intent = new Intent(this,NumActivity.class);
        startActivity(intent);
    }

}
